#ifndef __SEARCH_API_H__
#define __SEARCH_API_H__
#pragma once

struct STErrorInfo;

struct STSearchRequest
{
	std::string query;
	std::string index_name;
	std::string fetch_fields;
	std::string qp;
	std::string disable;
	std::string first_formula_name;
	std::string formula_name;
	std::string summary;
};

struct STSearchResponse
{
	std::string request_id;
	std::string status;
	float searchtime;
	uint32_t total;
	uint32_t num;
	uint32_t viewtotal;
	std::string items;
	std::string facet;
	std::string tracer;
	std::vector<STErrorInfo> errorList;
};

struct STScanRequest
{
	std::string scroll;
	std::string search_type;
	std::string scroll_id;
	std::string index_name;
	std::string query;
};

struct STScanResponse
{
	std::string request_id;
	std::string status;
	float searchtime;
	uint32_t total;
	uint32_t num;
	uint32_t viewtotal;
	std::string scroll_id;
	std::string items;
	std::string facet;
	std::string tracer;
	std::vector<STErrorInfo> errorList;
};

class DLL_OPENSEARCH_API CSearch
{
public:
	static CSearch* getInstance();

	bool Initialize(std::string host);
	bool Destory();

	STSearchResponse* search(STSearchRequest *pRequest);
	bool searchResponse();

	STScanResponse* scan(STScanRequest *pRequest);
	bool scanResponse();

	STSearchResponse m_searchResponse;
	STScanResponse m_scanResponse;
	std::string m_strUrl;
	std::map<std::string, std::string> m_mapRequestParameter;
	std::vector<std::string> m_vecRequestParameter;
private:
	CSearch();
	~CSearch();
};

#endif